package us.wili.dev.common.util.httpclient;

import org.apache.http.HttpHost;

/**
 * Created by JasonY on 17/6/3.
 */
public class RequestProperties {

    public class Proxy {
        private String hostName;
        private int port;
        private String scheme;

        public String getHostName() {
            return hostName;
        }

        public void setHostName(String hostName) {
            this.hostName = hostName;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public String getScheme() {
            return scheme;
        }

        public void setScheme(String scheme) {
            this.scheme = scheme;
        }
    }

    private boolean expectContinueEnabled = false;
    private String cookieSpec;
    private boolean redirectsEnabled = true;
    private boolean relativeRedirectsAllowed = true;
    private boolean circularRedirectsAllowed = false;
    private int maxRedirects = 50;
    private boolean authenticationEnabled = true;

    /**
     * 从连接池中获取连接的超时时间，超过该时间未拿到可用连接
     * 会抛出
     * org.apache.http.conn.ConnectionPoolTimeoutException:
     * Timeout waiting for connection from pool
     */
    private int connectionRequestTimeout = 1000;

    // 连接上服务器(握手成功)的时间，超出该时间抛出connect timeout
    private int connectTimeout = 3000;

    // 服务器返回数据(response)的时间，超过该时间抛出read timeout
    private int socketTimeout = 6000;
    private boolean contentCompressionEnabled = true;
    private Proxy proxy;

    public HttpHost httpProxy() {
        if (proxy == null) {
            return null;
        }

        return new HttpHost(proxy.getHostName(), proxy.getPort(), proxy.getScheme());
    }

    public boolean isExpectContinueEnabled() {
        return expectContinueEnabled;
    }

    public void setExpectContinueEnabled(boolean expectContinueEnabled) {
        this.expectContinueEnabled = expectContinueEnabled;
    }

    public String getCookieSpec() {
        return cookieSpec;
    }

    public void setCookieSpec(String cookieSpec) {
        this.cookieSpec = cookieSpec;
    }

    public boolean isRedirectsEnabled() {
        return redirectsEnabled;
    }

    public void setRedirectsEnabled(boolean redirectsEnabled) {
        this.redirectsEnabled = redirectsEnabled;
    }

    public boolean isRelativeRedirectsAllowed() {
        return relativeRedirectsAllowed;
    }

    public void setRelativeRedirectsAllowed(boolean relativeRedirectsAllowed) {
        this.relativeRedirectsAllowed = relativeRedirectsAllowed;
    }

    public boolean isCircularRedirectsAllowed() {
        return circularRedirectsAllowed;
    }

    public void setCircularRedirectsAllowed(boolean circularRedirectsAllowed) {
        this.circularRedirectsAllowed = circularRedirectsAllowed;
    }

    public int getMaxRedirects() {
        return maxRedirects;
    }

    public void setMaxRedirects(int maxRedirects) {
        this.maxRedirects = maxRedirects;
    }

    public boolean isAuthenticationEnabled() {
        return authenticationEnabled;
    }

    public void setAuthenticationEnabled(boolean authenticationEnabled) {
        this.authenticationEnabled = authenticationEnabled;
    }

    public int getConnectionRequestTimeout() {
        return connectionRequestTimeout;
    }

    public void setConnectionRequestTimeout(int connectionRequestTimeout) {
        this.connectionRequestTimeout = connectionRequestTimeout;
    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public int getSocketTimeout() {
        return socketTimeout;
    }

    public void setSocketTimeout(int socketTimeout) {
        this.socketTimeout = socketTimeout;
    }

    public boolean isContentCompressionEnabled() {
        return contentCompressionEnabled;
    }

    public void setContentCompressionEnabled(boolean contentCompressionEnabled) {
        this.contentCompressionEnabled = contentCompressionEnabled;
    }

    public Proxy getProxy() {
        return proxy;
    }

    public void setProxy(Proxy proxy) {
        this.proxy = proxy;
    }
}